var sqlite3 = require('sqlite3').verbose();
var jsontoxml = require('jsontoxml');

var SimpleNodebe = function() {
        this.db = new sqlite3.Database(':memory:');
};

var throw500 = function(callback) {
    process.nextTick(function() {
        callback(500);
    });
}

var returnResponse = function(callback, response) {
    process.nextTick(function() {
        callback(null, jsontoxml(response));
    });
}

SimpleNodebe.prototype.BatchDeleteAttributes = function(params, callback) {
    if (typeof params.DomainName !== 'string') {
        throw500(callback);
        return;
    }
    var domainName = params.DomainName;
    returnResponse(callback, {
        "BatchDeleteResponse": {}
    });
}
SimpleNodebe.prototype.BatchPutAttributes = function(params, callback) {
    if (typeof params.DomainName !== 'string') {
        throw500(callback);
        return;
    }
    var domainName = params.DomainName;
    returnResponse(callback, {
        "BatchPutAttributesResponse": {}
    });
}
SimpleNodebe.prototype.CreateDomain = function(params, callback) {
    if (typeof params.DomainName !== 'string') {
        throw500(callback);
        return;
    }
    var domainName = params.DomainName;
    var regex = /^[a-zA-Z_\-\.]{3,255}$/;
    if (regex.test(domainName)) {
        throw500(callback);
        return;
    }
    returnResponse(callback, {
        "CreateDomainResponse": {}
    });
}
SimpleNodebe.prototype.DeleteAttributes = function(params, callback) {
    if (typeof params.DomainName !== 'string') {
        throw500(callback);
        return;
    }
    var domainName = params.DomainName;

    if (typeof params.ItemName !== 'string') {
        throw500(callback);
        return;
    }
    var itemName = params.ItemName;
    var attributes = params.Attribute
    returnResponse(callback, {
        "DeleteAttributesResponse": {}
    });
}
SimpleNodebe.prototype.DeleteDomain = function(params, callback) {
    if (typeof params.DomainName !== 'string') {
        throw500(callback);
        return;
    }
    var domainName = params.DomainName;
    returnResponse(callback, {
        "DeleteDomainResponse": {}
    });
}
SimpleNodebe.prototype.DomainMetadata = function(params, callback) {
    if (typeof params.DomainName !== 'string') {
        throw500(callback);
        return;
    }
    var domainName = params.DomainName;
    returnResponse(callback, {
        "DomainMetadataResponse": {}
    });
}
SimpleNodebe.prototype.GetAttributes = function(params, callback) {
    if (typeof params.DomainName !== 'string') {
        throw500(callback);
        return;
    }
    var domainName = params.DomainName;
    returnResponse(callback, {
        "DeleteDomainResponse": {}
    });

    if (typeof params.ItemName !== 'string') {
        throw500(callback);
        return;
    }
    var itemName = params.ItemName;
    var attributeNames = params.AttributeName;
    var consistentRead = params.ConsistentRead || false;

    returnResponse(callback, {
        "GetAttributesResponse": {}
    });
}
SimpleNodebe.prototype.ListDomains = function(params, callback) {
    if (params.MaxNumberOfDomains < 0 || params.MaxNumberOfDomains > 100) {
        throw500(callback);
        return;
    }
    var maxNumberOfDomains = (params.MaxNumberOfDomains || 100);
    returnResponse(callback, {
        "ListDomainsResponse": {}
    });
}
SimpleNodebe.prototype.PutAttributes = function(params, callback) {
    if (typeof params.DomainName !== 'string') {
        throw500(callback);
        return;
    }
    var domainName = params.DomainName;

    if (typeof params.ItemName !== 'string') {
        throw500(callback);
        return;
    }
    var itemName = params.ItemName;
    console.log(params);
    returnResponse(callback, {
        "PutAttributesResponse": {}
    });
}
SimpleNodebe.prototype.Select = function(params, callback) {
    if (typeof params.SelectExpression !== 'string') {
        throw500(callback);
        return;
    }
    var selectExpression = params.SelectExpression;
    returnResponse(callback, {
        "SelectResponse": {}
    });
}
exports.SimpleNodebe = SimpleNodebe;
